/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DB;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author weidas
 */
@Entity
@Table(name = "User")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "User.findAll", query = "SELECT u FROM User u"),
    @NamedQuery(name = "User.findById", query = "SELECT u FROM User u WHERE u.id = :id"),
    @NamedQuery(name = "User.findByName", query = "SELECT u FROM User u WHERE u.name = :name"),
    @NamedQuery(name = "User.findByEmail", query = "SELECT u FROM User u WHERE u.email = :email"),
    @NamedQuery(name = "User.findByPassword", query = "SELECT u FROM User u WHERE u.password = :password"),
    @NamedQuery(name = "User.findBySalt", query = "SELECT u FROM User u WHERE u.salt = :salt")})
public class User implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Column(name = "name")
    private String name;
    @Column(name = "email")
    private String email;
    @Column(name = "password")
    private String password;
    @Column(name = "salt")
    private String salt;
    @ManyToMany(mappedBy = "userCollection", fetch = FetchType.EAGER)
    private Collection<Interest> interestCollection;
    @JoinTable(name = "Friends", joinColumns = {
        @JoinColumn(name = "requester_id", referencedColumnName = "id")}, inverseJoinColumns = {
        @JoinColumn(name = "receiver_id", referencedColumnName = "id")})
    @ManyToMany(fetch = FetchType.EAGER)
    private Collection<User> userCollection;
    @ManyToMany(mappedBy = "userCollection", fetch = FetchType.EAGER)
    private Collection<User> userCollection1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user", fetch = FetchType.EAGER)
    private Collection<Login> loginCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user", fetch = FetchType.EAGER)
    private Collection<PrivateMessage> privateMessageCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user1", fetch = FetchType.EAGER)
    private Collection<PrivateMessage> privateMessageCollection1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user", fetch = FetchType.EAGER)
    private Collection<StatusMessage> statusMessageCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user", fetch = FetchType.EAGER)
    private Collection<ChatMessage> chatMessageCollection;

    public User() {
    }

    public User(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    @XmlTransient
    public Collection<Interest> getInterestCollection() {
        return interestCollection;
    }

    public void setInterestCollection(Collection<Interest> interestCollection) {
        this.interestCollection = interestCollection;
    }

    @XmlTransient
    public Collection<User> getUserCollection() {
        return userCollection;
    }

    public void setUserCollection(Collection<User> userCollection) {
        this.userCollection = userCollection;
    }

    @XmlTransient
    public Collection<User> getUserCollection1() {
        return userCollection1;
    }

    public void setUserCollection1(Collection<User> userCollection1) {
        this.userCollection1 = userCollection1;
    }

    @XmlTransient
    public Collection<Login> getLoginCollection() {
        return loginCollection;
    }

    public void setLoginCollection(Collection<Login> loginCollection) {
        this.loginCollection = loginCollection;
    }

    @XmlTransient
    public Collection<PrivateMessage> getPrivateMessageCollection() {
        return privateMessageCollection;
    }

    public void setPrivateMessageCollection(Collection<PrivateMessage> privateMessageCollection) {
        this.privateMessageCollection = privateMessageCollection;
    }

    @XmlTransient
    public Collection<PrivateMessage> getPrivateMessageCollection1() {
        return privateMessageCollection1;
    }

    public void setPrivateMessageCollection1(Collection<PrivateMessage> privateMessageCollection1) {
        this.privateMessageCollection1 = privateMessageCollection1;
    }

    @XmlTransient
    public Collection<StatusMessage> getStatusMessageCollection() {
        return statusMessageCollection;
    }

    public void setStatusMessageCollection(Collection<StatusMessage> statusMessageCollection) {
        this.statusMessageCollection = statusMessageCollection;
    }

    @XmlTransient
    public Collection<ChatMessage> getChatMessageCollection() {
        return chatMessageCollection;
    }

    public void setChatMessageCollection(Collection<ChatMessage> chatMessageCollection) {
        this.chatMessageCollection = chatMessageCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof User)) {
            return false;
        }
        User other = (User) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "DB.User[ id=" + id + " ]";
    }
    
}
